package com.googlecode.curvedmetromaps.core.geometry;

import org.jbox2d.common.Vec2;

public abstract class QuadraticBezier implements Curve {

	@Override
	public Vec2 interpolate(float t) {
		Vec2 p0 = getP0();
		Vec2 p1 = getP1();
		Vec2 cp = getCP();

		return new Vec2((1f - t) * (1f - t) * p0.x + 2f * (1 - t) * t * cp.x + t * t * p1.x, (1f - t) * (1f - t) * p0.y
				+ 2f * (1 - t) * t * cp.y + t * t * p1.y);
	}

	public abstract Vec2 getP0();

	public abstract Vec2 getP1();

	public abstract Vec2 getCP();

	public Vec2 pointProjection(Vec2 _p) {
		// degree of input Bezier curve
		int n = 2;

		// array of control points
		Vec2[] v = { getP0(), getCP(), getP1() };

		return BezierUtil.pointProjection(_p, v);
	}
}
